﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace cpe.cpein.SERVER.Tools
{
    public static partial class ObjectConverter
    {
        /// <summary>
        /// Function used to convert a WS Group to a Data Group.
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public static DATA.Group GroupConverter(Group Group)
        {
            if (Group == null)
                return null;

            return new DATA.Group()
            {
                grp_id = Group.Id,
                grp_type = Group.IDType,
                grp_isworkable = Group.IsWorkable,
                grp_label = Group.Label,
                grp_isdeleted = Group.IsDeleted,
                grp_description = Group.Description,
            };
        }

        /// <summary>
        /// Function used to convert a Data Group to a WS Group.
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public static Group GroupConverter(DATA.Group Group)
        {
            if (Group == null)
                return null;
            GroupType grt = Tools.ObjectConverter.GroupTypeConverter(BUSINESS.BUGroupType.GetGroupTypeByID(Group.grp_type));
            return new Group()
            {
                Id = Group.grp_id,
                IsWorkable = Group.grp_isworkable,
                Label = Group.grp_label,
                IDType = Group.grp_type,
                Type = grt,
                IsDeleted = Group.grp_isdeleted,
                Description = Group.grp_description,
            };
        }

        /// <summary>
        /// Function used to convert a list of Data Groups to a List of WS Groups.
        /// </summary>
        /// <param name="Groups"></param>
        /// <returns></returns>
        public static List<Group> GroupConverter(List<DATA.Group> Groups)
        {
            List<Group> res = new List<Group>();
            foreach (DATA.Group us in Groups)
                res.Add(Tools.ObjectConverter.GroupConverter(us));

            return res;
        }

        /// <summary>
        /// Function used to convert a list of WS Groups to a List of Data Groups.
        /// </summary>
        /// <param name="Groups"></param>
        /// <returns></returns>
        public static List<DATA.Group> GroupConverter(List<Group> Groups)
        {
            List<DATA.Group> res = new List<DATA.Group>();
            foreach (Group us in Groups)
                res.Add(Tools.ObjectConverter.GroupConverter(us));

            return res;
        }
    }
}